﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PUCP.SI2.SGIRP.BE;
using PUCP.SI2.SGIRP.BC;

namespace PUCP.SI2.SGIRP.GUI
{
    public partial class LoginForm : Form
    {
        UsuarioBC gUsuario = new UsuarioBC(); 
        public LoginForm()
        {
            InitializeComponent();
            lblError.Text = "";
        }

        private void Login_RealPlaza_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void btnCerrar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            int x;
            PrincipalForm vPrincipal = new PrincipalForm();
            String usuario, contrasena;
            UsuarioBE user = null;
            lblError.Hide();
            usuario = txtUser.Text.ToUpper();
            contrasena = txtContrasena.Text;
            user = gUsuario.AsignarValores(usuario, contrasena);
            x = gUsuario.validarUsuario(user);
            if (x == 1)
            {
                txtUser.Text = "";
                txtContrasena.Text = "";
                vPrincipal.Show();
                vPrincipal.SetRefLogin(this);
                this.Hide();
            }
            else
            {
                lblError.Text = "*Usuario o contraseña incorrecta";
                lblError.Show();
            } 
        }
    }
}
